<template>
	<view class="container-bg">
		<view class="pad-30">
			<view class="list-box">
				<u-swipe-action>
					<u-swipe-action-item class="mar-bottom-30" :options="options1" @click="hanldeRome"
						v-for="item in linked_acctlist">
						<view class="list radius14 pad-30">
							<view class="font-32 color-white">{{item.linked_brbankname}}</view>
							<view class="font-32 mar-top-30 color-white">{{getString(item.linked_acctno)}}</view>
						</view>
					</u-swipe-action-item>
				</u-swipe-action>
			</view>
			<view @click="hanldeAdd" class="addCard mar-top-30 font-28">+ 添加银行卡</view>
		</view>
	</view>
</template>

<script>
	// 接口地址
	import {
		backCardGetAll,
		bindAdd,
		unlinkBankCard,
		llPwdToken
	} from '@/config/api.js'
	import {
		llWallet
	} from '@/config/url.js'
	export default {
		data() {
			return {
				linked_acctlist: [],
				options1: [{
					text: '解绑'
				}]
			}
		},
		onLoad() {
			this.getDataList();
		},
		methods: {
			// 解绑银行卡
			hanldeRome(e) {
				// #ifdef APP-PLUS
				uni.showToast({
					title: 'app暂时不支持，请前往h5解绑',
					icon: 'none'
				})
				// #endif
				
				// #ifdef H5
				llPwdToken({
					password_scene: 'bind_card_password',
					flag_chnl: 'H5',
				}).then(res => {

					// 以下参数通过服务端获取
					lianlianpay.invokePasswordControl({
						passwordScene: 'bind_card_password',
						oidPartner: res.data.oid_partner, // 商户号
						userId: res.data.user_id, // 用户号
						passwordElementToken: res.data.password_element_token, // 向服务端请求生成的 token
						env: llWallet, // 默认 production-生产 ste
						styles: { // 样式集合
							themeColor: '#0E59F0', // 主题颜色（按钮等）
						}
					}, (res) => {
						let data = {
							plat_id: 11,
							ll_data: {
								linked_acctno: this.linked_acctlist[e.index].linked_acctno,
								password: res.data.password,
								random_key: res.data.randomKey,
							}
						}
						unlinkBankCard(data).then(unlin => {
							uni.showToast({
								title: unlin.msg
							})
							this.getDataList();
						})
					})
				})
				// #endif
			},
			// 连连钱包绑卡
			hanldeAdd() {
				uni.showLoading({
					title: '加载中...',
					mask: true,
				})
				bindAdd({
					plat_id: 11
				}).then(res => {

					let {
						gateway_url
					} = res.data.ll_data;

					// #ifdef APP-PLUS
					let url =
						`https://h5.xuenuo8.cn/llPay.html?url=${encodeURIComponent(gateway_url)}`
					plus.runtime.openURL(url)
					// #endif
					// #ifdef H5
					window.location.href = gateway_url
					// #endif

					uni.hideLoading();
				})
			},
			// 字符串替换
			getString(text) {
				if (text) {
					return text.replace(/().*(.{4})/, "**** **** **** $2")
				}
			},
			// 获取银行卡
			getDataList() {
				backCardGetAll({
					plat_id: 11
				}).then(res => {
					this.linked_acctlist = res.data.linked_acctlist
				})
			}

		}
	}
</script>

<style scoped lang="scss">
	.container-bg {
		background: #eee;
		height: 100vh;

		::v-deep .u-swipe-action-item__content {
			background: rgb(199, 198, 205);
		}

		::v-deep .u-swipe-action-item__right__button__wrapper {
			border-radius: 0 14rpx 14rpx 0 !important;

		}
	}

	.list {
		background: #259e4d;
		overflow: hidden;
	}

	.addCard {
		text-align: center;
		height: 194rpx;
		line-height: 194rpx;
		color: #000;
		background: #dedede;
		border-radius: 14rpx;
	}
</style>